package com.huawei.hms.support.api.hwid;

import android.text.TextUtils;
import com.huawei.hms.core.aidl.annotation.Packed;
import com.huawei.hms.support.api.client.Result;
import com.huawei.hms.support.api.client.Status;
import com.huawei.updatesdk.service.otaupdate.UpdateKey;
import org.json.JSONException;
import org.json.JSONObject;

public class RevokeAccessResult extends Result {
    @Packed
    private Integer errorCode;
    @Packed
    private String errorMsg;

    public RevokeAccessResult(Integer num, String str) {
        this.errorCode = num;
        this.errorMsg = str;
    }

    public Integer getErrorCode() {
        return this.errorCode;
    }

    public void setErrorCode(Integer num) {
        this.errorCode = num;
    }

    public String getErrorMsg() {
        return this.errorMsg;
    }

    public void setErrorMsg(String str) {
        this.errorMsg = str;
    }

    public RevokeAccessResult(Status status) {
        setStatus(status);
    }

    public boolean isSuccess() {
        return getStatus().isSuccess();
    }

    public RevokeAccessResult fromJson(String str) throws JSONException {
        if (!TextUtils.isEmpty(str)) {
            jsonToSuper(new JSONObject(str));
        }
        return this;
    }

    private void jsonToSuper(JSONObject jSONObject) {
        JSONObject optJSONObject = jSONObject.optJSONObject(UpdateKey.STATUS);
        if (optJSONObject != null) {
            setStatus(new Status(optJSONObject.optInt("statusCode"), optJSONObject.optString("statusMessage", null)));
        }
    }

    public RevokeAccessResult getBeanFromJsonStr(String str) {
        if (TextUtils.isEmpty(str)) {
            return new RevokeAccessResult();
        }
        try {
            Integer valueOf;
            JSONObject jSONObject = new JSONObject(str);
            if (jSONObject.has("errorCode")) {
                valueOf = Integer.valueOf(jSONObject.getInt("errorCode"));
            } else {
                valueOf = null;
            }
            return new RevokeAccessResult(valueOf, jSONObject.getString("errorMsg"));
        } catch (JSONException e) {
            return new RevokeAccessResult();
        }
    }
}
